package com.dsw.demo.rabbitmq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * FanoutRabbitMQ 配置类
 *
 * @author keyu.wang
 * @date 2018/5/7 10:40
 */
@Configuration
public class FanoutRabbitMQConfig {

    public static final String FANOUT_EXCHANGE = "fanout.exchange";//消息交换机
    public static final String FANOUTQUEUEA = "fanout.queue.a";//消息队列名a
    public static final String FANOUTQUEUEB = "fanout.queue.b";//消息队列名b
    public static final String FANOUTQUEUEC = "fanout.queue.c";//消息队列名c


    @Bean(name = "FanoutQueueA")
    public Queue queueA() {
        return new Queue(FANOUTQUEUEA);
    }

    @Bean(name = "FanoutQueueB")
    public Queue queueB() {
        return new Queue(FANOUTQUEUEB);
    }

    @Bean(name = "FanoutQueueC")
    public Queue queueC() {
        return new Queue(FANOUTQUEUEC);
    }

    /**
     * FanoutExchange: 将消息分发到所有的绑定队列，无routingkey的概念
     *
     * @param
     * @author keyu.wang
     * @date 2018/5/7 17:08
     */
    @Bean(name = "FanoutExchange")
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUT_EXCHANGE);//配置广播路由器
    }

    @Bean
    Binding bindingQueueA2Exchange(@Qualifier("FanoutQueueA") Queue queue, @Qualifier("FanoutExchange") FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }

    @Bean
    Binding bindingQueueB2Exchange(@Qualifier("FanoutQueueB") Queue queue, @Qualifier("FanoutExchange") FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }

    @Bean
    Binding bindingQueueC2Exchange(@Qualifier("FanoutQueueC") Queue queue, @Qualifier("FanoutExchange") FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }

}
